// Copyright (c) 2015-2021 Jeevanandam M (jeeva@myjeeva.com), All rights reserved.
// mamba source code and usage is governed by a MIT style
// license that can be found in the LICENSE file.

// Package mamba provides Simple HTTP and REST client library for Go.
package mamba

import (
	http "github.com/Danny-Dasilva/fhttp"
	cookiejar "github.com/Danny-Dasilva/fhttp/cookiejar"
	"golang.org/x/net/publicsuffix"
	"net"
)

// Version # of mamba
const Version = "2.7.0"

// New method creates a new mamba client.
func New() *Client {
	cookieJar, _ := cookiejar.New(&cookiejar.Options{PublicSuffixList: publicsuffix.List})
	return createClient(&http.Client{
		Jar: cookieJar,
	})
}

func NewWithRoundTripper(ja3, ua string) *Client {
	cookieJar, _ := cookiejar.New(&cookiejar.Options{PublicSuffixList: publicsuffix.List})
	//cookieJar, _ := persistentCookiejar.New(&persistentCookiejar.Options{PublicSuffixList: publicsuffix.List})
	//transport, err := NewTransport("771,4865-4866-4867-49195-49199-49196-49200-52393-52392-49171-49172-156-157-47-53,0-23-65281-10-11-35-16-5-13-18-51-45-43-27-21,29-23-24,0")
	return createClient(&http.Client{
		Transport: CreateRoundTripper(ja3, ua),
		Jar:       cookieJar,
	})
}

// NewWithClient method creates a new mamba client with given `http.Client`.
func NewWithClient(hc *http.Client) *Client {
	return createClient(hc)
}

// NewWithLocalAddr method creates a new mamba client with given Local Address
// to dial from.
func NewWithLocalAddr(localAddr net.Addr) *Client {
	cookieJar, _ := cookiejar.New(&cookiejar.Options{PublicSuffixList: publicsuffix.List})
	return createClient(&http.Client{
		Jar:       cookieJar,
		Transport: createTransport(localAddr),
	})
}
